/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BDIngresosConfigurar.java
 *
 * Created on 06/20/2011, 02:17:39 PM
 */
package org.gingresos.recibos;

import java.io.InputStream;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.view.JasperViewer;
import org.gingresos.clases.reportes.MyRecibosDetalles;
import org.sirmupadbapi.beans.*;
import org.gingresos.start.MySesion;
import org.sirmupadbapi.controller.*;
import org.sirmupadbapi.generales.Mensajeria;

/**
 *
 * @author avbravo
 */
public class RecibosReimprimir extends javax.swing.JInternalFrame {

    DefaultTableModel modelo;
    int fila = -1;
    Bicicles bicicletas1 = new Bicicles();
    BiciclesController bicicletasController1 = new BiciclesController();
    Codigosrecargo codigosrecargo1 = new Codigosrecargo();
    CodigosrecargoController codigosrecargoController1 = new CodigosrecargoController();
    Comercios comercios1 = new Comercios();
    ComerciosController comerciosController1 = new ComerciosController();
    Contribuyentes contribuyentes1 = new Contribuyentes();
    ContribuyentesController contribuyentesController1 = new ContribuyentesController();
    Corregimients corregimientos1 = new Corregimients();
    CorregimientsController corregimientosController1 = new CorregimientsController();
    MyRecibosDetalles myRecibosDetalles1 = new MyRecibosDetalles();
    Recibes recibos1 = new Recibes();
    RecibesController recibosController1 = new RecibesController();
    Recibesdetalles recibosDetalles1 = new Recibesdetalles();
    RecibesdetallesController recibosdetallesController1 = new RecibesdetallesController();
    Regimen regimen1 = new Regimen();
    RegimenController regimenController1 = new RegimenController();
    Remolques remolques1 = new Remolques();
    RemolquesController remolquesController1 = new RemolquesController();
      Remolquestraspaso remolquestraspaso1 = new Remolquestraspaso();
    RemolquestraspasoController remolquestraspasoController1 = new RemolquestraspasoController();
    Usuarios usuarios1 = new Usuarios();
    UsuariosController usuariosController1 = new UsuariosController();
    Vehicles vehiculos1 = new Vehicles();
    VehiclesController vehiculosController1 = new VehiclesController();
    VehiclestraspasoController vehiclestraspasoController1 = new VehiclestraspasoController();
    Vehiclestraspaso vehiclestraspaso1 = new Vehiclestraspaso();
 Integer idrecibo;
    String usuarioimprime;
    String cedularuc;
    String nombre, direccion, parametroplaca;
    String idcorregimiento;
    String idrecargo = "";
    Integer paginas;
    String tipo_recibo = "";
    List<MyRecibosDetalles> listMyRecibosDetallesPage1 = new ArrayList<MyRecibosDetalles>();
    List<MyRecibosDetalles> listMyRecibosDetallesPage2 = new ArrayList<MyRecibosDetalles>();
    List<MyRecibosDetalles> listMyRecibosDetallesPage3 = new ArrayList<MyRecibosDetalles>();

    /**
     * Creates new form BDIngresosConfigurar
     */
    public RecibosReimprimir() {
        initComponents();

        java.util.Calendar ca = java.util.Calendar.getInstance();

        java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());

        int year = ca.get(java.util.Calendar.YEAR);
        jTextFieldAnio.setText(String.valueOf(year));
        modelo = (DefaultTableModel) jTable1.getModel();
        String sql = "idmunicipio='" + MySesion.getIdmunicipio() + "' and activo='si'";

        if (codigosrecargoController1.query(sql)) {
            for (Codigosrecargo codigosrecargo : codigosrecargoController1.getCodigosrecargolist()) {
                idrecargo = codigosrecargo.getIDREGIMENRECARGO();
            }
        }
        if (idrecargo.equals("")) {
            Mensajeria.Mensaje("No se ha creado los codigos de recargo");
            jButtonGuardar.setEnabled(false);
            jButtonConsultar.setEnabled(false);
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldRecibo = new javax.swing.JTextField();
        jButtonGuardar = new javax.swing.JButton();
        jButtonCerrar = new javax.swing.JButton();
        jLabelAnulado = new javax.swing.JLabel();
        jTextFieldAnulado = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldFecha = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldPagador = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldDireccion = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldCedulaRuc = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldAcuerdo = new javax.swing.JTextField();
        jButtonConsultar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldAnio = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldTipo = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldTipoRecibo = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jTextFieldTotalPagado = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTextFieldTotalExonerado = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldPlaca = new javax.swing.JTextField();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Reeimpresion de  Recibo");

        jLabel2.setText("Recibo");

        jTextFieldRecibo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldReciboActionPerformed(evt);
            }
        });

        jButtonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gingresos/resources/gif/print.png"))); // NOI18N
        jButtonGuardar.setToolTipText("Guardar");
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        jButtonCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gingresos/resources/gif/return.png"))); // NOI18N
        jButtonCerrar.setToolTipText("Regresar");
        jButtonCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCerrarActionPerformed(evt);
            }
        });

        jLabelAnulado.setText("Anulado");

        jTextFieldAnulado.setEditable(false);

        jLabel3.setText("Fecha");

        jTextFieldFecha.setEditable(false);

        jLabel4.setText("Pagado por");

        jTextFieldPagador.setEditable(false);

        jLabel5.setText("Direccion");

        jTextFieldDireccion.setEditable(false);

        jLabel6.setText("Cedula/RUC");

        jTextFieldCedulaRuc.setEditable(false);

        jLabel7.setText("Acuerdo");

        jTextFieldAcuerdo.setEditable(false);

        jButtonConsultar.setText("Consultar");
        jButtonConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConsultarActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "recargo", "codigo", "regimen", "saldo ant.", "pago", "descuento", "saldo", "comentario"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jLabel8.setText("Año");

        jLabel9.setText("Tipo");

        jTextFieldTipo.setEditable(false);
        jTextFieldTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldTipoActionPerformed(evt);
            }
        });

        jLabel10.setText("Tipo Recibo");

        jTextFieldTipoRecibo.setEditable(false);

        jLabel11.setText("Total Pagado");

        jLabel12.setText("Total Exonerado");

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gingresos/resources/gif/clear.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel13.setText("Placa");

        jTextFieldPlaca.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 761, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel7)
                                    .addGap(38, 38, 38))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel3)
                                            .addComponent(jLabel5))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(70, 70, 70)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTextFieldPagador, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel6))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTextFieldFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabelAnulado)
                                        .addGap(18, 18, 18)
                                        .addComponent(jTextFieldAnulado, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(40, 40, 40)
                                        .addComponent(jLabel9)))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldCedulaRuc, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldTipoRecibo, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jTextFieldTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTextFieldAcuerdo, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(66, 66, 66)
                                        .addComponent(jLabel10))
                                    .addComponent(jTextFieldDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldPlaca, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTextFieldRecibo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel8)
                                        .addGap(18, 18, 18)
                                        .addComponent(jTextFieldAnio, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jButtonConsultar)))
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addGap(427, 427, 427))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(77, 77, 77)
                        .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldTotalPagado, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldTotalExonerado, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel13)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldAnio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonConsultar)
                    .addComponent(jTextFieldRecibo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelAnulado)
                        .addComponent(jTextFieldAnulado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9)
                        .addComponent(jTextFieldTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldPagador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6)
                        .addComponent(jTextFieldCedulaRuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(jTextFieldAcuerdo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel10)
                    .addComponent(jTextFieldTipoRecibo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(jTextFieldPlaca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldTotalPagado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jTextFieldTotalExonerado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonGuardar, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE)
                    .addComponent(jButtonCerrar, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE))
                .addGap(53, 53, 53))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 875, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 10, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed
        try {

             PrinterRecibos pr = new PrinterRecibos();
//        pr.setIdcorregimiento(idRegimen);
        pr.setIdmunicipio(MySesion.getIdmunicipio());
        this.idrecibo =Integer.parseInt(jTextFieldRecibo.getText());
     pr.setIdrecibo(this.idrecibo);
        pr.setMunicipio(MySesion.getMunicipio());
        pr.setPaginas(paginas);
        pr.ImprimirRecibo();
//            HashMap map = new HashMap();
////            Imprimir(listMyRecibosDetalles, map);
//            switch (this.paginas) {
//                case 1:
//                    Imprimir(listMyRecibosDetallesPage1, map);
//                    break;
//                case 2:
//                    ImprimirPaginas(listMyRecibosDetallesPage1, map, "2_1");
//                    ImprimirPaginas(listMyRecibosDetallesPage2, map, "2_2");
//                    break;
//                case 3:
//                    ImprimirPaginas(listMyRecibosDetallesPage1, map, "3_1");
//                    ImprimirPaginas(listMyRecibosDetallesPage2, map, "3_2");
//                    ImprimirPaginas(listMyRecibosDetallesPage3, map, "3_3");
//                    break;
//                default:
//                    Mensajeria.Mensaje("Demasiados impuestos por imprimir");
//                    return;
//
//
//            }

        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "Imprimir()");
        }
    }//GEN-LAST:event_jButtonGuardarActionPerformed

    private void jButtonCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCerrarActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jButtonCerrarActionPerformed

    private void jTextFieldReciboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldReciboActionPerformed
        ConsultarRecibo();
    }//GEN-LAST:event_jTextFieldReciboActionPerformed

    private void jButtonConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConsultarActionPerformed
        ConsultarRecibo();
    }//GEN-LAST:event_jButtonConsultarActionPerformed

    private void jTextFieldTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldTipoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldTipoActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Limpiar();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new ServidorIngresosCrear().setVisible(true);
//            }
//        });
//    }
//    
    private void ConsultarRecibo() {
        try {

            Limpiar();
            if (modelo != null) {
                while (modelo.getRowCount() > 0) {
                    modelo.removeRow(0);
                }
            }
            jTextFieldPlaca.setText("");
            if (jTextFieldRecibo.equals("")) {
                Mensajeria.Mensaje("Ingrese el numero de recibo");
                return;
            }
            if (jTextFieldAnio.getText().equals("")) {
                Mensajeria.Mensaje("Ingrese el año");
                return;
            }
            String sql = "idrecibo='" + jTextFieldRecibo.getText() + "' and idmunicipio='" + MySesion.getIdmunicipio() + "'";
            if (!recibosController1.query(sql)) {
                Mensajeria.Mensaje("No existe un recibo con ese numero");
                return;
            }
            recibos1 = recibosController1.getRecibeslist().get(0);
            if (recibos1.getAnulado().equals("si")) {

                jLabelAnulado.setForeground(java.awt.Color.red);
                jLabelAnulado.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gingresos/resources/gif/error.gif"))); // NOI18N

            } else {

                jLabelAnulado.setForeground(javax.swing.UIManager.getDefaults().getColor("TextField.foreground"));
                jLabelAnulado.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gingresos/resources/gif/ok.png"))); // NOI18N

            }
            jTextFieldTotalPagado.setText(String.valueOf(recibos1.getTotalpagado()));
            jTextFieldTotalExonerado.setText(String.valueOf(recibos1.getTotalexonerado()));
            Format formatter;
            formatter = new SimpleDateFormat("dd/MM/yyyy");
            Date fecha = recibos1.getFecha();
            String MyFecha = formatter.format(fecha);
            jTextFieldFecha.setText(MyFecha);

            jTextFieldAnulado.setText(recibos1.getAnulado());

            jTextFieldAcuerdo.setText(recibos1.getIdexonerado());
            jTextFieldTipo.setText(recibos1.getTipoid());
            jTextFieldTipoRecibo.setText(recibos1.getTiporecibo());


            usuarios1.setUsername(recibos1.getIdusuario());
            Usuarios usuarios = usuariosController1.findByPrimaryKey(usuarios1);
            if (usuarios == null) {
                Mensajeria.Mensaje("No existe un usuario registrado que emitio el recibo");
                usuarioimprime = "";
            } else {
                usuarios1 = usuarios;
                usuarioimprime = usuarios1.getUsuario();
            }
            if (recibos1.getTipoid().equals("comercios")) {
                comercios1.setIDCOMERCIO(recibos1.getId());
                comercios1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                CargarComercios();
                CargarRecibos();
                parametroplaca = "";
                jTextFieldPlaca.setText("");

            } else {
                if (recibos1.getTipoid().equals("contribuyentes")) {
                    contribuyentes1.setCEDULA(recibos1.getId());
                    contribuyentes1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                    CargarContribuyentes();
                    CargarRecibos();
                    parametroplaca = "";
                    jTextFieldPlaca.setText("");
                } else {
                    /*
                     * bicicletas
                     */
                    if (recibos1.getTipoid().equals("bicicletas")) {
                        CargarBicicletas();
                        CargarRecibos();

                    } else {
                        /*
                         * remolques
                         */
                        if (recibos1.getTipoid().equals("remolques")) {
                            CargarRemolques();
                            CargarRecibos();
                        } else {
                            if (recibos1.getTipoid().equals("vehiculos")) {
                                CargarVehiculos();
                                CargarRecibos();
                            }
                        }
                    }

                }


            }

        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "ConsultarRecibo()");
        }
    }

    private void CargarComercios() {
        try {
            Comercios comercios = comerciosController1.findByPrimaryKey(comercios1);
            if (comercios == null) {
                Mensajeria.Mensaje("No existe un comercio con ese codigo: " + comercios1.getIDCOMERCIO());
                return;
            }
            comercios1 = comercios;
            jTextFieldPagador.setText(comercios1.getCOMERCIO());
            nombre = comercios1.getCOMERCIO();
            jTextFieldCedulaRuc.setText(comercios1.getRUC());
            cedularuc = comercios1.getRUC();

            CargarDireccion(comercios1.getIDCORREGIMIENTO());
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "CargarComercios()");
        }
    }

    private void CargarContribuyentes() {
        try {
            Contribuyentes contribuyentes = contribuyentesController1.findByPrimaryKey(contribuyentes1);
            if (contribuyentes == null) {
                Mensajeria.Mensaje("No existe un contribuyente con esa cedula: " + contribuyentes1.getCEDULA());
                return;
            }
            contribuyentes1 = contribuyentes;
            jTextFieldPagador.setText(contribuyentes.getCONTRIBUYENTE());
            nombre = contribuyentes1.getCONTRIBUYENTE();
            jTextFieldCedulaRuc.setText(contribuyentes.getCEDULA());
            cedularuc = contribuyentes.getCEDULA();
            CargarDireccion(contribuyentes1.getIDCORREGIMIENTO());
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "CargarContribuyentes()");
        }
    }

    private void CargarBicicletas() {
        try {

            bicicletas1.setIDBICICLETA(Long.parseLong(recibos1.getId()));
            bicicletas1.setIDMUNICIPIO(MySesion.getIdmunicipio());
            Bicicles bicicletas = bicicletasController1.findByPrimaryKey(bicicletas1);
            if (bicicletas == null) {
                Mensajeria.Mensaje("No existe una bicicleta con el codigo " + bicicletas1.getID());
                return;
            }
            bicicletas1 = bicicletas;
            parametroplaca = "PLACA: " + bicicletas.getPLACA();
            jTextFieldPlaca.setText(bicicletas.getPLACA());
            //Encontrar el dueño
            if (bicicletas1.getTIPOID().equals("contribuyentes")) {
                contribuyentes1.setCEDULA(bicicletas1.getID());
                contribuyentes1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                CargarContribuyentes();
            } else {
                if (bicicletas1.getTIPOID().equals("comercios")) {
                    comercios1.setIDCOMERCIO(bicicletas1.getID());
                    comercios1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                    CargarComercios();
                }
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "CargarBicicletas()");
        }

    }

    private void CargarRemolques() {
        try {
             if (recibos1.getTiporecibo().equals("vehiculostraspaso")) {
                String sql = "idremolque='" + recibos1.getId() + "' and idrecibo='" + recibos1.getIdrecibo() + "'";
                if (remolquestraspasoController1.query(sql)) {
                   Remolquestraspaso remolquestraspaso = remolquestraspasoController1.getRemolquestraspasolist().get(0);
                    if (remolquestraspaso != null) {
//                        vehiculos1.setIDVEHICULO(Long.parseLong(vehiclestraspaso.getID()));
                        if (remolquestraspaso.getTIPOID().equals("contribuyentes")) {
                            contribuyentes1.setCEDULA(remolquestraspaso.getID());
                            contribuyentes1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                            CargarContribuyentes();
                            return;
                        } else {
                            if (remolquestraspaso.getTIPOID().equals("comercios")) {
                                comercios1.setIDCOMERCIO(remolquestraspaso.getID());
                                comercios1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                                CargarComercios();
                                return;
                            }
                        }
                    } 
                }
            }
            remolques1.setIDREMOLQUE(Long.parseLong(recibos1.getId()));
            remolques1.setIDMUNICIPIO(MySesion.getIdmunicipio());
            Remolques remolques = remolquesController1.findByPrimaryKey(remolques1);
            if (remolques == null) {
                Mensajeria.Mensaje("No existe un remolque con el codigo " + remolques1.getID());
                return;
            }
            remolques1 = remolques;
            parametroplaca = "PLACA: " + remolques1.getPLACA();
            jTextFieldPlaca.setText(remolques1.getPLACA());
            //Encontrar el dueño
            if (remolques1.getTIPOID().equals("contribuyentes")) {
                contribuyentes1.setCEDULA(remolques1.getID());
                contribuyentes1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                CargarContribuyentes();
            } else {
                if (remolques1.getTIPOID().equals("comercios")) {
                    comercios1.setIDCOMERCIO(remolques1.getID());
                    comercios1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                    CargarComercios();
                }
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "CargarRemolques()");
        }
    }

    private void CargarVehiculos() {
        try {
   
            if (recibos1.getTiporecibo().equals("vehiculostraspaso")) {
                      
                String sql = "idvehiculo='" + recibos1.getId() + "' and idrecibo='" + recibos1.getIdrecibo() + "'";
                if (vehiclestraspasoController1.query(sql)) {
                          
                    Vehiclestraspaso vehiclestraspaso = vehiclestraspasoController1.getVehiclestraspasolist().get(0);
                    if (vehiclestraspaso != null) {
                            
//                        vehiculos1.setIDVEHICULO(Long.parseLong(vehiclestraspaso.getID()));
                        if (vehiclestraspaso.getTIPOID().equals("contribuyentes")) {
                               
                            contribuyentes1.setCEDULA(vehiclestraspaso.getID());
                            contribuyentes1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                            CargarContribuyentes();
                            return;
                        } else {
                            if (vehiclestraspaso.getTIPOID().equals("comercios")) {
                              
                                comercios1.setIDCOMERCIO(vehiclestraspaso.getID());
                                comercios1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                                CargarComercios();
                                return;
                            }
                        }
                    } 
                }
            } 
           
            vehiculos1.setIDVEHICULO(Long.parseLong(recibos1.getId()));
            vehiculos1.setIDMUNICIPIO(MySesion.getIdmunicipio());
            Vehicles vehiculos = vehiculosController1.findByPrimaryKey(vehiculos1);

            if (vehiculos == null) {
                Mensajeria.Mensaje("No existe un vehiculos con el codigo " + vehiculos1.getID());
                return;
            }
            vehiculos1 = vehiculos;
            parametroplaca = "PLACA: " + vehiculos1.getPLACA();
            jTextFieldPlaca.setText(vehiculos1.getPLACA());
            //Encontrar el dueño
            if (vehiculos1.getTIPOID().equals("contribuyentes")) {
                contribuyentes1.setCEDULA(vehiculos1.getID());
                contribuyentes1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                CargarContribuyentes();
            } else {
                if (vehiculos1.getTIPOID().equals("comercios")) {
                    comercios1.setIDCOMERCIO(vehiculos1.getID());
                    comercios1.setIDMUNICIPIO(MySesion.getIdmunicipio());
                    CargarComercios();
                }
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "CargarVehiculos()");
        }
    }

    private void CargarDireccion(String idcorregimiento) {
        try {
            corregimientos1.setIdcorregimiento(idcorregimiento);
            Corregimients corregimients = corregimientosController1.findByPrimaryKey(corregimientos1);
            if (corregimients == null) {
                Mensajeria.Mensaje("No existe un corregimiento con el codigo " + corregimientos1.getIdcorregimiento());
                return;
            }

            corregimientos1 = corregimients;
            jTextFieldDireccion.setText(corregimientos1.getCorregimiento());
            direccion = corregimientos1.getCorregimiento();

        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "CargarDireccion()");
        }
    }

    private void CargarRecibos() {
        try {

            String sql = "idrecibo= '" + recibos1.getIdrecibo() + "' and idmunicipio='" + MySesion.getIdmunicipio() + "'";
            if (recibosdetallesController1.query(sql)) {
                Object[] filas = new Object[8];
                listMyRecibosDetallesPage1.removeAll(listMyRecibosDetallesPage1);
                listMyRecibosDetallesPage2.removeAll(listMyRecibosDetallesPage2);
                listMyRecibosDetallesPage3.removeAll(listMyRecibosDetallesPage3);
                String lidregimen = "";
                Integer contador = 0;
                Integer numeroRegistros = recibosdetallesController1.getRecibesdetalleslist().size();
                if (numeroRegistros <= 9) {
                    this.paginas = 1;
                } else {
                    if (numeroRegistros >= 10 && numeroRegistros <= 18) {
                        this.paginas = 2;
                    } else {
                        if (numeroRegistros >= 19 && numeroRegistros <= 27) {
                            this.paginas = 3;
                        }
                    }
                }
                for (Recibesdetalles recibosdetalles : recibosdetallesController1.getRecibesdetalleslist()) {
                    contador++;
                    regimen1.setIdregimen(recibosdetalles.getIdregimen());
                    regimen1.setIdmunicipio(recibosdetalles.getIdmunicipio());
                    filas[1] = recibosdetalles.getIdregimen();
                    lidregimen = recibosdetalles.getIdregimen();
                    if (recibosdetalles.getEsrecargo().equals("no")) {
                        filas[0] = new Boolean(false);
                    } else {

                        filas[0] = new Boolean(true);
                        filas[1] = idrecargo;
                        lidregimen = idrecargo;
                    }

                    Regimen regimen = regimenController1.findByPrimaryKey(regimen1);
                    if (regimen == null) {
                        Mensajeria.Mensaje("No existe un regimen con el codigo: " + regimen1.getIdregimen());
                        filas[2] = "";
                    } else {


                        filas[2] = regimen.getRegimen();


                        if (contador <= 9) {
                            listMyRecibosDetallesPage1.add(new MyRecibosDetalles(nombre, direccion,
                                    MySesion.getMunicipio(), recibos1, regimen.getRegimen(), lidregimen, MySesion.Redondeo(recibosdetalles.getSaldoanterior()),
                                    MySesion.Redondeo(recibosdetalles.getPago()),
                                    MySesion.Redondeo(recibosdetalles.getExoneracion()),
                                    MySesion.Redondeo(recibosdetalles.getSaldo()), recibosdetalles.getComentario()));
                        }
                        if (contador >= 10 && contador <= 18) {
                            listMyRecibosDetallesPage2.add(new MyRecibosDetalles(nombre, direccion,
                                    MySesion.getMunicipio(), recibos1, regimen.getRegimen(), lidregimen, MySesion.Redondeo(recibosdetalles.getSaldoanterior()),
                                    MySesion.Redondeo(recibosdetalles.getPago()),
                                    MySesion.Redondeo(recibosdetalles.getExoneracion()),
                                    MySesion.Redondeo(recibosdetalles.getSaldo()), recibosdetalles.getComentario()));
                        } else {
                            if (contador >= 19 && contador <= 27) {
                                listMyRecibosDetallesPage3.add(new MyRecibosDetalles(nombre, direccion,
                                        MySesion.getMunicipio(), recibos1, regimen.getRegimen(), lidregimen, MySesion.Redondeo(recibosdetalles.getSaldoanterior()),
                                        MySesion.Redondeo(recibosdetalles.getPago()),
                                        MySesion.Redondeo(recibosdetalles.getExoneracion()),
                                        MySesion.Redondeo(recibosdetalles.getSaldo()), recibosdetalles.getComentario()));
                            }
                        }

                    }



                    filas[3] = MySesion.Redondeo(recibosdetalles.getSaldoanterior());
                    filas[4] = MySesion.Redondeo(recibosdetalles.getPago());
                    filas[5] = MySesion.Redondeo(recibosdetalles.getExoneracion());
                    filas[6] = MySesion.Redondeo(recibosdetalles.getSaldo());

                    filas[7] = recibosdetalles.getComentario();
                    modelo.addRow(filas);
                }

            } else {
                Mensajeria.Mensaje("No existen registros de detalles de recibos con ese numero");
                return;
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "CargarRecibos()");
        }

    }

    private void Limpiar() {
        jTextFieldAcuerdo.setText("");
        jTextFieldAnulado.setText("");
        jTextFieldCedulaRuc.setText("");
        jTextFieldDireccion.setText("");
        jTextFieldFecha.setText("");
        jTextFieldPagador.setText("");
        jTextFieldTipo.setText("");
        jTextFieldTipoRecibo.setText("");
        jTextFieldTotalExonerado.setText("");
        jTextFieldTotalPagado.setText("");

    }

    private void Imprimir(List<MyRecibosDetalles> aux, HashMap map) throws JRException {
        try {
            map.put("P_NOMBREUSUARIO", usuarioimprime);
            map.put("P_CEDULARUC", cedularuc);
            map.put("P_PLACA", parametroplaca);
            JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(aux);
            InputStream reporte = (InputStream) getClass().getResourceAsStream("/org/gingresos/reportes/recibos/Recibos.jasper");
            if (reporte == null) {
                Mensajeria.Mensaje("No se pudo cargar el reporte");
            } else {
                JasperPrint print = JasperFillManager.fillReport(reporte, map, ds);
                JasperViewer.viewReport(print, false);
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "Imprimir()");
        }
    }

    private void ImprimirPaginas(List<MyRecibosDetalles> aux, HashMap map, String control) throws JRException {
        try {
            map.put("P_NOMBREUSUARIO", usuarioimprime);
            map.put("P_CEDULARUC", cedularuc);
            map.put("P_PLACA", parametroplaca);
            JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(aux);
            InputStream reporte = null;
            reporte = (InputStream) getClass().getResourceAsStream("/org/gingresos/reportes/recibos/Recibos_" + control + ".jasper");


            if (reporte == null) {
                Mensajeria.Mensaje("No se pudo cargar el reporte");
            } else {
                JasperPrint print = JasperFillManager.fillReport(reporte, map, ds);
                JasperViewer.viewReport(print, false);
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "Imprimir()");
            System.out.println(" ex" + ex);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonCerrar;
    private javax.swing.JButton jButtonConsultar;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelAnulado;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextFieldAcuerdo;
    private javax.swing.JTextField jTextFieldAnio;
    private javax.swing.JTextField jTextFieldAnulado;
    private javax.swing.JTextField jTextFieldCedulaRuc;
    private javax.swing.JTextField jTextFieldDireccion;
    private javax.swing.JTextField jTextFieldFecha;
    private javax.swing.JTextField jTextFieldPagador;
    private javax.swing.JTextField jTextFieldPlaca;
    private javax.swing.JTextField jTextFieldRecibo;
    private javax.swing.JTextField jTextFieldTipo;
    private javax.swing.JTextField jTextFieldTipoRecibo;
    private javax.swing.JTextField jTextFieldTotalExonerado;
    private javax.swing.JTextField jTextFieldTotalPagado;
    // End of variables declaration//GEN-END:variables
}
